package behavior;


import lejos.robotics.subsumption.Behavior;
import motor.carrito;

/**
 * @version   1.0

 * @author    Bruno Argenta, Esteban Arrua, Luis Galusso
 * @copyright (C) 2012 Bruno Argenta, Esteban Arrua, Luis Galusso
 * @contact   b.argenta@gmail.com, estarr2212@gmail.com, lgalusso@gmail.com
 *
 * @license        GNU/GPLv3
 * This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see http://www.gnu.org/licenses/.
 *
 *
*/


public class DriveForward implements Behavior { 
	private carrito carro;
	private boolean suppress=false;
	//private NXTConnection connector;
	//private DataOutputStream dos;
	//private DataInputStream dis;
	
	
	public DriveForward(carrito carro) {
		// TODO Auto-generated constructor stub
				
		
		this.carro = carro;
	}
	
	public boolean takeControl() {
		// TODO Auto-generated method stub
		//.println("Tomo control Drive");
		return true;
	}

	public void action() {
		// TODO Auto-generated method stub
//		this.connector = RS485.getConnector().connect("GRP062", NXTConnection.RAW);
//		this.dos = this.connector.openDataOutputStream();
//		this.dis = this.connector.openDataInputStream();
//		barredora bar = new barredora();
		suppress = false;
		
		//bar.activar();
		
//		try {
//			this.dos.writeInt(1);
//			this.dos.flush();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		try {
//			this.dis.readInt();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		carro.SetMovingSpeed(250);
		//carro.resetTacho();
		carro.Forward();
		while(!suppress)
			Thread.yield();
		//carro.Stop();
//		try {
//			this.dos.writeInt(0);
//			this.dos.flush();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		try {
//			this.dis.readInt();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		try {
//			this.dos.close();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		this.connector.close();
//		
//		this.connector = RS485.getConnector().connect("GRP062", NXTConnection.RAW);
//		this.dos = this.connector.openDataOutputStream();
//		
//		try {
//			this.dos.writeInt(0);
//			this.dos.flush();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		
//		try {
//			this.dos.close();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		this.connector.close();
		//bar.desactivar();
	}

	public void suppress() {
		// TODO Auto-generated method stub
		//.println("Suprimir DriveForward");
		suppress=true;
		
	}

}


